#ifndef _BASIC_UTILS_HH_
#define _BASIC_UTILS_HH_

#include <string>
#include <sstream>
#include <iostream>

#include <cxcore.h>
#include <cv.h>
#include <highgui.h>


template <class T>
bool from_string(T& t, 
                 const std::string& s, 
                 std::ios_base& (*f)(std::ios_base&) = std::dec)
{
  std::istringstream iss(s);
  return !(iss >> f >> t).fail();
}

template <typename T>
std::string to_string(const T &thing) {
    std::stringstream os;
    os << thing;
    return os.str();
}


void deleteIplImage(IplImage *img);
void deleteCvMat(CvMat *mat);

void deleteFileStorage(CvFileStorage *fs);

void deleteVideoWriter(CvVideoWriter *vw);

void deleteCvKalman(CvKalman *kalman);

void print_arr(const CvArr *arr, bool transpose = false, const char *format = NULL);
void print_arr_mul(const CvArr *arr, float mul, bool transpose = false, const char *format = NULL);


bool is_box_in_image(const CvRect r, const IplImage *img);

void AgruparMatriz(CvMat * mat, CvMat *small, CvMat *mask);
void AgruparMatriz(CvMat ** mat, CvMat *small, CvMat *mask);
CvMat * AgruparMatriz2new(CvMat * mat, CvMat *mask);
void AgruparMatriz(CvMat * mat, CvMat *mask);
int DeleteRow(CvMat **mat, int n);
void AddRow(CvMat * mat);
CvMat * AddRow2new(CvMat * mat);
void AddRow2new(CvMat **mat);


#endif
